package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.TeachplanDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.TeachplanVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.content.domain.Teachplan;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    // 查询课程计划
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public ResponseResult treeNodes(@PathVariable("courseId") Long courseId){// 接收参数
        // 调用方法 返回结果
       return teachplanService.treeNodes(courseId);

        //return teachplanService.treeNodes2(courseId);

    }
    // 保存或者修改课程计划
    @PostMapping("/teachplan")
    public ResponseResult updateTeachplan(@RequestBody TeachplanDto dto){ //接收参数
        //  调用方法 返回结果
    return teachplanService.updateTeachplan(dto);

    }
    // 删除课程计划
    @DeleteMapping("/teachplan/{id}")
    public ResponseResult deleteTeachPlan(@PathVariable("id") Long id){ // 接收参数
        // 调用方法 返回结果
        return teachplanService.deleteTeachPlan(id);
    }

    // 根据id查询课程计划
    @GetMapping("/teachplan/{teachplanId}")
    public ResponseResult findteachplan(@PathVariable("teachplanId") Long teachplanId){ // 接收参数
        // 调用方法
        Teachplan teachplan = teachplanService.getById(teachplanId);
        // 封装VO
        TeachplanVo vo = BeanHelper.copyProperties(teachplan, TeachplanVo.class);
        // 返回结果
        return ResponseResult.okResult(vo);
    }




}
